package com.jd.jr.insights.dm.dim.controller;

import com.jd.jr.insights.dm.dim.domain.Department;
import com.jd.jr.insights.dm.dim.service.DeptService;
import com.jd.jr.insights.dm.dim.service.impl.DeptServiceImpl;
import com.jd.jr.insights.dm.dim.util.LOG;
import com.jfinal.core.Controller;

import java.util.Enumeration;

/**
 * Created by Administrator on 2017/7/15.
 */
public class DeptController extends Controller {


    DeptService deptService=new DeptServiceImpl();
    public void index() {
        render("/dept.html");
    }

    public void getAllTreeEnumList() {
        int dept_id = getParaToInt("dimId");
        LOG.INFO("dimId", dept_id + "");
        renderText("");
    }


    public void getAllDeptList() {
       LOG.INFO("getAllDeptList()",deptService.getDeptListJson());
        renderText(deptService.getDeptListJson());
    }

    public void getAllDeptListNm() {
        LOG.INFO("getAllDeptList()",deptService.getDeptListJson());
        renderText(deptService.getDeptListJsonNm());
    }



    public void save() {

        Integer parent_id=getParaToInt("parent_id");
        String code=getPara("code");
        String desc=getPara("desc");
        String name=getPara("value");
        Integer level=getParaToInt("level");

        Department dept=new Department();

        dept.setCode(code);
        dept.setValue(name);
        dept.setParent_id(parent_id);
        dept.setDesc(desc);
        dept.setLevel(level);
        renderText(deptService.save(dept));
    }

    public void update() {
        Enumeration e = getAttrNames();
        while (e.hasMoreElements()) {
            Object o = e.nextElement();
            LOG.INFO("update()",o.toString());
        }
        Integer id=getParaToInt("id");
        String code=getPara("code");
        String name=getPara("value");
        String desc=getPara("desc");


        Department dept=new Department();
        dept.setId(id);
        dept.setCode(code);
        dept.setValue(name);
        dept.setDesc(desc);
        renderText(deptService.update(dept));

    }

    public void deleteById(){
        Integer id=getParaToInt("id");
        Department dept=new Department();
        dept.setId(id);
        renderText(deptService.deleteById(dept));
    }


    public void getByDimDefId(){
        Enumeration e = getAttrNames();
        while (e.hasMoreElements()) {
            Object o = e.nextElement();
            LOG.INFO("deleteById()",o.toString());
        }
        renderText("");
    }

    public void generateLvlTableData(){

    }

    public void saveTreeToLvl(){

    }
}
